﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            if (batNgoaiLe())
            {
                txtKetQua.Text = "";
                int so = Int32.Parse(txtSo.Text);
                if (cbGiaTri.SelectedItem != null)
                {
                    if (cbGiaTri.SelectedItem.ToString().Equals("Chẵn"))
                    {
                        
                        int i = 0;
                        while (true)
                        {
                            if(i%2==0)
                            {
                                txtKetQua.AppendText(i.ToString() + " ");
                                i+=2;
                            }
                            if (i > so) break;
                        }
                    }
                    else if (cbGiaTri.SelectedItem.ToString().Equals("Lẻ"))
                    {
                        
                        int i = 0;
                        while (true)
                        {
                            if (i % 2 != 0)
                            {
                                txtKetQua.AppendText(i.ToString() + " ");
                                i+=2;
                            }
                            if (i > so) break;
                        }
                    }
                }
            }
        }
        public Boolean batNgoaiLe()
        {
            int x = 0;
            if (txtSo.Text.Equals(""))
            {
                MessageBox.Show("Chưa Nhập");
                return false;
            }
            else if (Int32.TryParse(txtSo.Text, out x) == false)
            {
                MessageBox.Show("Sai kieu");
                return false;
            }
            return true;
        }
    }
}
